package main

import "fmt"

func main() {
	nums := make([]int, 0, 10)
	for i := 1; i <= 10; i++ {
		nums = append(nums, i)
	}
	index := TwoSumHash(nums, 10)
	fmt.Printf("index1: %d, value1: %d; index2: %d, value2: %d: \n", index[0], nums[index[0]], index[1], nums[index[1]])
}

func TwoSumEnum(nums []int, target int) (int, int) {
	for i, _ := range nums {
		for j, _ := range nums[i+1:] {
			if nums[i]+nums[j] == target {
				return i, j
			}
		}
	}
	return 0, 0
}

func TwoSumHash(nums []int, target int) []int {
	hashTable := make(map[int]int)
	for i, num := range nums {
		if p, ok := hashTable[target-num]; ok {
			return []int{p, i}
		}
		hashTable[num] = i
	}
	return nil
}
